package com.jsg.sl651.entity.station;

import com.jsg.sl651.enums.StationType;
import com.jsg.sl651.enums.WaterSystemZoningCode;
import com.jsg.sl651.enums.WatershedCode;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class AddressOfHydrologicalTelemetryStation implements RemoteTelemetryStationAddress {
    // 原始报文
    private final String originalMessage;
    // 流域区代码
    private final WatershedCode watershedCode;
    // 水系统分区代码
    private final WaterSystemZoningCode waterSystemZoningCode;
    // 测站类型
    private final StationType stationType;
    // 测站编号型代码
    private final String numberTypeCode;
    public AddressOfHydrologicalTelemetryStation(String originalMessage) {
        if (originalMessage == null || originalMessage.length() != 10 || !originalMessage.startsWith("00")) {
            throw new IllegalArgumentException("originalMessage is null or length is not 10 or not start with 00");
        }
        this.originalMessage = originalMessage;
        this.watershedCode = WatershedCode.getByCode(Integer.parseInt(originalMessage.substring(2, 3), 16));
        this.waterSystemZoningCode = WaterSystemZoningCode.getByCode(watershedCode, Integer.parseInt(originalMessage.substring(3, 5), 16));
        this.stationType = StationType.getByCode(Integer.parseInt(originalMessage.substring(5, 6), 16));
        this.numberTypeCode = originalMessage.substring(6, 10);
    }

    @Override
    public String getMessageHex() {
        return originalMessage;
    }

    @Override
    public String toString() {
        return "遥测站信息{" +
                "原始报文=" + originalMessage + "," +
                "流域区=" + watershedCode.getName() + "," +
                "水系统分区=" + waterSystemZoningCode.getName() + "," +
                "测站类型=" + stationType.getName() + "," +
                "测站编号型代码=" + numberTypeCode +
                "}";
    }
}
